<?php
//author: weibo.com/10coder 

/*base类*/
class api3_base {
	protected $errno = 0;
	protected $errno2 = 0;
 	protected $driver_name = 'api3_base';
	
	public function __construct($driver='api3_base') {
		$this->driver($driver);
	}
	
	/*dump函数*/
	protected function dump($a) {
		print_r($a);
		return $this;
	}
	
	/*测试*/
	public function test() {
		$this->dump('test');
		return $this;
	}
	
	//错误号函数族	
	public function errno(&$errno) {
		$errno = $this->errno;
		return $this;
	}

	public function isok($errno=null, &$obj=null) { 
		$obj=$this; 
		if($errno === null) $errno = $this->errno;
		return !$errno;
	}

	protected function seterrno($errno, $errno2=0) {
		$this->errno = $errno;
		$this->errno2 = $errno2;
	}

	//错误号函数族
	
	//驱动器函数族
	public function driver($name) { 
		$this->driver_name = $name; 
		return $this;
	}
	
	public function drivername(&$name) {
		$name = $this->driver_name;
		return $this;
	}
	//驱动器函数族
	
	//默认处理	
	public function __call($name, $arguments) {
		//添加其他默认处理方法
		//....
		
		$this->errno = API3_ERR_NOFUN;
		return $this;
	}	
	
	//工厂方法
	public function factory() {
		$class_name = $this->driver_name;
		if(class_exists($class_name)) {
			return new $class_name();
		} else 
			return new api3_base();
	}
	
	//帮助提示，根据错误类型给出具体方法
	public function help(&$message) {
		return $this;
	}
	
	//http
	protected function load_http() {
		require_once(dirname(__FILE__) . '/http.lib.php');
	}
	
	//end
}

